package com.oscarmovie.action;

import java.util.List;
import java.util.Set;

import com.opensymphony.xwork2.ActionSupport;
import com.oscarmovie.Constants;
import com.oscarmovie.model.Award;
import com.oscarmovie.model.Calendar;
import com.oscarmovie.model.Mpac;
import com.oscarmovie.service.AwardService;
import com.oscarmovie.service.CalendarService;

public class AwardAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private AwardService awardService;
	private Award award;
	private List<Award> awards;
	
	
	public String execute() throws Exception {
		throw new Exception("Please specify method name!");
	}
	public String add() throws Exception {
		setAward(null);
		return Constants.ADD;
	}
	public String edit() throws Exception {
		loadAll();
		load();
		return Constants.EDIT;
	}
	public String save() throws Exception {
		if(award.getId()!=0){
			
			Award dbAward = awardService.load(award.getId());
			dbAward.setName(award.getName());
			dbAward.setNameCn(award.getNameCn());
			dbAward.setAlias(award.getAlias());
			dbAward.setDescription(award.getDescription());
			
			award = dbAward;
		}
		awardService.save(award);
		return edit();
	}

	public String load() throws Exception {
		this.setAward(awardService.load(award.getId()));
		return SUCCESS;
	}
	
	public String loadAll() throws Exception {
		this.awards = awardService.loadAll();
		return SUCCESS;
	}
	public String select() throws Exception {
		loadAll();
		return Constants.SELECT;
	}
	public List<Award> getAwards() {
		return awards;
	}

	public void setAwardService(AwardService awardService) {
		this.awardService = awardService;
	}

	public void setAward(Award award) {
		this.award = award;
	}

	public Award getAward() {
		return award;
	}

}
